import request from '@/utils/request'
import { praseStrEmpty } from "@/utils/lfs";


// 查询产品列表
export function productList(query) {
  return request({
    url: '/lfs-admin/product/queryProductList',
    method: 'post',
    data: query
  })
}

// 查询产品详细
export function getProductInfo(id) {
  return request({
    url: '/lfs-admin/product/getProductInfo/' + praseStrEmpty(id),
    method: 'get'
  })
}

// 新增产品
export function addProductInfo(data) {
  return request({
    url: '/lfs-admin/product/addProductInfo',
    method: 'post',
    data: data
  })
}

// 修改产品
export function updateProductInfo(data) {
  return request({
    url: '/lfs-admin/product/updateProductInfo',
    method: 'put',
    data: data
  })
}

// 删除产品
export function delProductInfo(ids) {
  return request({
    url: '/lfs-admin/product/delProductInfo/' + ids,
    method: 'delete'
  })
}

// 数据包上传记录
export function dataPackageList(query) {
  return request({
    url: '/lfs-admin/dataPackage/list',
    method: 'post',
    data: query
  })
}

// 数据仓库列表
export function queryRepositoryList(data) {
  return request({
    url: '/lfs-admin/dataRepository/queryRepositoryList',
    method: 'post',
    data: data
  })
}

// 数据包上传




// 数据包上传记录
export function dataPackageUpload(data) {
  return request({
    url: '/lfs-admin/dataPackage/upload',
    method: 'post',
    data: data
  })
}

// 数据包解析
export function dataPackageAnalysis(data) {
  return request({
    url: '/lfs-admin/dataPackage/analysis',
    method: 'post',
    data: data
  })
}


// 查询产品详细
export function getUploadDetail(data) {
  return request({
    url: '/lfs-admin/dataPackage/getUploadDetail',
    method: 'post',
    data
  })
}


export function queryReleaseDetail(data) {
  return request({
    url: '/lfs-admin/dataRelease/queryReleaseDetail',
    method: 'post',
    data
  })
}


// 删除数据包记录
export function deleteData(id) {
  return request({
    url: `/lfs-admin/dataPackage/deleteData?ids=${id}`,
    method: 'delete'
  })
}


// 查询店铺列表
export function getShopList(data) {
  return request({
    url: '/lfs-admin/shop/list',
    method: 'post',
    data: data
  })
}

// 删除数据包记录
export function deleteShop(id) {
  return request({
    url: '/lfs-admin/shop/delete?id=' + id,
    method: 'delete'
  })
}


// 获取授权地址
export function getOauthUrl(data) {
  return request({
    url: '/lfs-admin/platform/getOauthUrl',
    method: 'post',
    data
  })
}

// 查询平台列表
export function platformList(data) {
  return request({
    url: '/lfs-admin/platform/list',
    method: 'post',
    data
  })
}

// 查询已过期或即将过期的店铺信息
export function queryExpireShopList() {
  return request({
    url: '/lfs-admin/shop/queryExpireShopList',
    method: 'post'
  })
}



// 获取accessToken
export function getAccessToken(data) {
  return request({
    url: '/lfs-admin/platform/getAccessToken',
    method: 'post',
    data
  })
}


export function getMallInfo(data) {
  return request({
    url: '/lfs-admin/platform/getMallInfo',
    method: 'post',
    data
  })
}



// 生成随机店铺id
export function generateShopId() {
  return request({
    url: '/lfs-admin/shop/generateShopId',
    method: 'get',
  })
}


// 新增店铺
export function addShopInfo(data) {
  return request({
    url: '/lfs-admin/shop/addShopInfo',
    method: 'post',
    data
  })
}

// 同步数据
export function synchronousData(shopId, token) {
  return request({
    url: `/lfs-admin/dataRepository/synchronousData?shopId=${shopId}&accessToken=${token}`,
    method: 'post',
  })
}

export function searchPddBrand(catId, value, shopId) {
  return request({
    url: `/lfs-admin/dataRepository/searchPddBrand?catId=${catId}&value=${value}&shopId=${shopId}`,
    method: 'post',
  })
}

// 查询当前用户下可用的店铺列表
export function getCurrUserShopAllData(data) {
  return request({
    url: '/lfs-admin/dataRepository/getCurrUserShopAllData',
    method: 'post',
    data
  })
}

// 获取商品类目信息
export function getCurrentCommodityCategory(name, token, shopId) {
  return request({
    url: `/lfs-admin/dataRepository/getCurrentCommodityCategory?name=${name}&accessToken=${token}&shopId=${shopId}`,
    method: 'post',
  })
}

export function queryShopListById(shopIds, token) {
  return request({
    url: `/lfs-admin/dataRepository/queryShopListById?shopIds=${shopIds}&accessToken=${token}`,
    method: 'post',
  })
}


export function productPropertyTemplateList(shopId) {
  return request({
    url: `/lfs-admin/dataRepository/productPropertyTemplateList?shopId=${shopId}`,
    method: 'post',
  })
}


export function updateOrAddProductPropertyTemp(data) {
  return request({
    url: '/lfs-admin/dataRepository/updateOrAddProductPropertyTemp',
    method: 'post',
    data
  })
}


export function deleteProductPropertyTempById(id) {
  return request({
    url: `/lfs-admin/dataRepository/deleteProductPropertyTempById?id=${id}`,
    method: 'delete'
  })
}



export function getDefaultTitle(ids) {
  return request({
    url: `/lfs-admin/dataRepository/getDefaultTitle?ids=${ids}`,
    method: 'post'
  })
}


// 查询商品款式、风格、保护套质地、流行元素、自定义规格通用接口

export function getNodeData(catPropId, accessToken, shopId) {
  return request({
    url: `/lfs-admin/dataRepository/getNodeData?catPropId=${catPropId}&accessToken=${accessToken}&shopId=${shopId}`,
    method: 'post'
  })
}

// 延长生效时间
export function prolongExpireTime(id) {
  return request({
    url: `/lfs-admin/dataRepository/prolongExpireTime?id=${id}`,
    method: 'get',
  })
}

// 生成副本
export function copySeries(id, count) {
  return request({
    url: `/lfs-admin/dataRepository/copySeries?id=${id}&count=${count}`,
    method: 'get',
  })
}

// 删除数据包
export function deleteRepository(id) {
  return request({
    url: `/lfs-admin/dataRepository/deleteRepository?ids=${id}`,
    method: 'delete'
  })
}


// 查询产品数据列表
export function queryProductRecordList(data) {
  return request({
    url: '/lfs-admin/dataRepository/queryProductRecordList',
    method: 'post',
    data
  })
}

// 根据ID删除产品数据
export function deleteProductRecordById(id) {
  return request({
    url: `/lfs-admin/dataRepository/deleteProductRecordById?id=${id}`,
    method: 'delete'
  })
}

// 修改产品名称
export function updateProductRecord(data) {
  return request({
    url: '/lfs-admin/dataRepository/updateProductRecord',
    method: 'post',
    data
  })
}

// 预发布查看
export function getProductGoodsData(id) {
  return request({
    url: `/lfs-admin/dataRepository/getProductGoodsData?id=${id}`,
    method: 'post'
  })
}

// 发布商品
export function releaseGoods(data) {
  return request({
    url: '/lfs-admin/dataRepository/releaseGoods',
    method: 'post',
    data
  })
}


// 获取自动标题模板
export function getTitleTemplates(data) {
  return request({
    url: '/lfs-admin/dataRepository/getTitleTemplates',
    method: 'post',
    data
  })
}

// 获取词库
export function getGainWord(titleTypeEnum) {
  return request({
    url: `/lfs-admin/dataRepository/gainWord?titleTypeEnum=${titleTypeEnum}`,
    method: 'post',
  })
}

// 更新自动标题模板
export function updateOrAddTitleTemplate(data) {
  return request({
    url: '/lfs-admin/dataRepository/updateOrAddTitleTemplate',
    method: 'post',
    data
  })
}

// 根据ID删除自动标题模板
export function deleteTitleTemplateById(id) {
  return request({
    url: `/lfs-admin//dataRepository/deleteTitleTemplateById?id=${id}`,
    method: 'delete',
  })
}

export function exportWillReleaseExcel(price, quantity, repositoryId, seriesName) {
  return request({
    url: `/lfs-admin/dataRepository/exportWillReleaseExcel?price=${price}&quantity=${quantity}&repositoryId=${repositoryId}&seriesName=${seriesName}`,
    method: 'post',
    responseType:'blob',
  })
}

export function importWillReleaseExcel(file, params) {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('pddProductPropertyDto', new Blob([JSON.stringify(params)], {type: 'application/json'}));

  return request({
    url: '/lfs-admin//dataRepository/importWillReleaseExcel',
    method: 'post',
    headers: {
        'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}
